function qs(ele) {
    return document.querySelector(ele)
}
axios.defaults.baseURL = 'http://124.223.14.236:3001/api'


//输入找回账号步骤
const [yi,er,san] = document.querySelectorAll('.step')
er.style.display = 'none'
san.style.display = 'none'
let id
qs('#one').addEventListener('click',async function () {
    const res = await axios({
        method: 'GET',
        url: '/user/findPwd',
        params: {
            phone: qs('#phone').value
        }
    })
    id = res.data.data.id
    // console.log(res)
    if (res.status !== 200) {
        return alert('手机号错误')
    }
    //手机号输入正确，进行下一个步骤
    yi.style.display = 'none'
    er.style.display = 'block'
    san.style.display = 'none'
    qs('#username').value = res.data.data.username
    qs('#mobile').value = res.data.data.phone
    qs('#question').value = res.data.data.question
})


//回答密保问题步骤
qs('#next').addEventListener('click', function () {
    if (qs('#answer').value.trim()) {
    yi.style.display = 'none'
    er.style.display = 'none'
    san.style.display = 'block'
    }else {
        return alert('请输入密保答案')
    }
})
qs('#prev').addEventListener('click', function () {
    yi.style.display = 'block'
    er.style.display = 'none'
    san.style.display = 'none'
})


//重置密码步骤
qs('#last').addEventListener('click',async function () {
    const res = await axios({
        method: 'POST',
        url: '/user/resetPwd',
        data: {
            id: JSON.stringify(id),
            password: qs('#newpassword').value,
            answer: qs('#answer').value
        }
    })
    // console.log(res)
    if (res.status === 200){
        return alert('密码修改成功') ,location.href = '/01-loginBaseCode/login.html' 
        
    }else {
        return alert('密码修改失败')
    }

})
qs('#er').addEventListener('click', function () {
    yi.style.display = 'none'
    er.style.display = 'block'
    san.style.display = 'none'
})